package com.sgb.kjwl.view.ui.adapter.transport;

import android.view.View;

import androidx.annotation.Nullable;
import androidx.databinding.ViewDataBinding;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.transport.GoodsSourcePlace;
import com.sgb.kjwl.model.entity.transport.SingleItemConstant;
import com.sgb.kjwl.model.entity.transport.common.AddressItem;

import java.util.List;

/**
 * @Author : 熊丽
 * @date :2021/1/23 0023$ 11:26$
 * @Description :货源详情地址适配器$
 */
public class GoodsDetailAddressAdapter extends BaseMultiItemQuickAdapter<AddressItem, BaseViewHolder> {

    private ItemOnClickListen mItemOnClickListen;
    private GoodsSourcePlace mPlace;

    public GoodsDetailAddressAdapter(@Nullable List<AddressItem> data, GoodsSourcePlace place) {
        super( data);
        this.mPlace = place;
        addItemType(SingleItemConstant.TYPE_ONE, R.layout.item_goods_detail_address);
    }
    public void SetItemOnClickListen(ItemOnClickListen item){
        this.mItemOnClickListen = item;
    }

    @Override
    protected void convert(BaseViewHolder helper, AddressItem item) {
        helper.setVisible(R.id.tv_line,item.isLines()?true:false);
        helper.setVisible(R.id.tv_distance,item.isLines()?true:false);
        helper.setImageResource(R.id.img_unload,item.getIcon());
        helper.setText(R.id.tv_distance,item.getDistance()==null?"":item.getDistance());
        helper.setText(R.id.tv_city_name,item.getAddressName());
        helper.setText(R.id.tv_detail_address,item.getAddressdetail());
        helper.setVisible(R.id.map_address,true);
        helper.getView(R.id.map_address).setOnClickListener((v) -> {
            mItemOnClickListen.onItemClick(mPlace,item.getType(),item.getPosition());
        });
    }
    @FunctionalInterface
    public interface ItemOnClickListen<T, B extends ViewDataBinding> {
        void onItemClick(GoodsSourcePlace place,String i,int position);
    }
}
